import 'dart:math';

import 'package:flutter/cupertino.dart';
import 'package:website.core/core/presentation/localization/translation.dart';
import 'package:website.core/core/presentation/theme/theme.dart';
import 'package:website.core/core/presentation/widgets/app_button.dart';
import 'package:website.core/core/presentation/widgets/header_action_dialog.dart';

class HeaderUserButton extends StatelessWidget {
  const HeaderUserButton({
    required this.iconSize,
    required this.onAccountTilePressed,
    required this.onSigningOutTilePressed,
    Key? key,
  }) : super(key: key);

  final double iconSize;
  final VoidCallback onAccountTilePressed;
  final VoidCallback onSigningOutTilePressed;

  void _onPressed({
    required BuildContext context,
  }) {
    showHeaderActionDialog(
      context: context,
      arrowDyOffset: -8.0,
      items: [
        HeaderActionDialogItem(
          icon: Icon(
            CupertinoIcons.person_crop_circle,
            color: CoreTheme.of(context).headerActionDialogTileIconColor,
            size: 24,
          ),
          title: CoreTranslation.of(context).headerUserActionDialogAccountActionTileTitle,
          onPressed: onAccountTilePressed,
        ),
        HeaderActionDialogItem(
          icon: Transform.rotate(
            angle: pi,
            child: Icon(
              CupertinoIcons.square_arrow_left,
              color: CoreTheme.of(context).headerActionDialogTileIconColor,
              size: 24,
            ),
          ),
          title: CoreTranslation.of(context).headerUserActionDialogSigningOutActionTileTitle,
          onPressed: onSigningOutTilePressed,
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {
    return AppButton(
      pressedOpacity: 0.6,
      onPressed: () {
        _onPressed(
          context: context,
        );
      },
      child: Padding(
        padding: const EdgeInsets.all(10.0),
        child: Icon(
          CupertinoIcons.person_circle,
          color: CoreTheme.of(context).headerUserButtonIconColor,
          size: iconSize,
        ),
      ),
    );
  }
}
